package com.yixun.lbx.controller.informationManagement;

import com.yixun.controller.BaseController;
import com.yixun.lbx.entity.YxProBreedKnowledge;
import com.yixun.lbx.service.BreedKnowledgeServie;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/bk")
public class BreedKnowledgeController extends BaseController {
    private final BreedKnowledgeServie knowledgeServie;

    public BreedKnowledgeController(BreedKnowledgeServie knowledgeServie) {
        this.knowledgeServie = knowledgeServie;
    }

    /*
     *获取养殖知识列表
     */
    @PostMapping("/getListByPage")
    public HashMap<String, Object> getListByPage(@RequestBody HashMap<String, Object> map) {
        Integer count = knowledgeServie.getCount(map);
        List<YxProBreedKnowledge> knowledges = knowledgeServie.getListByPage(map);

        map.put("count", count);
        map.put("knowledges", knowledges);
        return map;
    }

    /*
     *添加养殖知识
     */
    @PostMapping("/addKnowledge")
    public int addKnowledge(@RequestBody HashMap<String, Object> map) {
        map.put("addUser", this.getSessionUser().getUser_id());
        return knowledgeServie.addKnowledge(map);
    }

    /*
     *修改养殖知识
     */
    @PostMapping("/updateKnowledge")
    public int updateKnowledge(@RequestBody HashMap<String, Object> map) {
        map.put("updateUser", this.getSessionUser().getUser_id());
        return knowledgeServie.updateKnowledge(map);
    }

    /*
     *删除养殖知识
     */
    @PostMapping("/deleteKnowledge")
    public int deleteKnowledge(@RequestBody HashMap<String, Object> map) {
        map.put("updateUser", this.getSessionUser().getUser_id());
        String[] ids = map.get("id").toString().split(",");
        map.put("ids", ids);
        return knowledgeServie.deleteKnowledge(map);
    }

    @GetMapping("/getObjByArgs")
    public List<YxProBreedKnowledge> getObjByArgs(YxProBreedKnowledge knowledge) {
        return knowledgeServie.getObjByArgs(knowledge);
    }

    /*搜索*/
    @RequestMapping("/getSearchListByPage")
    public HashMap<String, Object> getSearchListByPage(@RequestBody HashMap<String, String> map) {
        HashMap<String, Object> hashMap = new HashMap<>();
        List<YxProBreedKnowledge> obj = knowledgeServie.getSearchListByPage(map);
        hashMap.put("obj", obj);
        hashMap.put("count", obj.size());
        return hashMap;
    }
}
